<?PHP


class permissions
{
	
	var $page;
	var $id;
	var $level;
	var $user;
	var $data;
	var $user_data;
	
	
	function permissions()
	{
		$this->user=$_SESSION['user_id'];
	}
	
	function include_page($page)
	{
		$this->page=$page;
		$isok=$this->check_permissions();
		if($isok)
		{
			//include $_GET['q'];
			include $page;
			mp('Permissions OK');
		}
		else
		{
			mp('Permissions FAIL');
			echo "Permission Denied";
		}
		
	}
	function check_permissions()
	{
		/*
			Logic:
			1. Check Page From DB
			2. Get User Level
			3. Get Permission Levels
			4. Match
			5. Return
		*/
		$this->page= strstr($this->page, '/');
		$user=new user;
		$user->user_id=$this->user;
		$user_data=$user->get_user_info();
		$ispagethere=$this->get_page_permissions();
		
		if($ispagethere)
		{
		//	//rp($this->data);
		//	//rp($user_data);
		
			foreach($this->data as $x)
			{
				if($user_data['user_level']==$x['level'])
				{
					return true;
				}
			}
		
			return false;
		
		}
		else
		{
			/*
				go
			*/
			return true;
		}
			return false;
	}
	
	function get_page_permissions()
	{
		$w[0]='page';
		$w[1]=$this->page;
		$w[2]='=';	
		$where[]=$w;
		$data=get_sql('permissions','id',$where,NULL);
		
		
		if(!empty($data))
		{
		//	$data=current($data);
			$this->data=$data;
			return true;
		}
		else
		{
			return false;
		}
		
		
	}
}
?>